home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / PIL / ImageTransform.py < prev    next >
Encoding:
Python Source  |  2006-12-03  |  2.6 KB  |  92 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id: ImageTransform.py 2813 2006-10-07 10:11:35Z fredrik $
  4. #
  5. # transform wrappers
  6. #
  7. # History:
  8. # 2002-04-08 fl   Created
  9. #
  10. # Copyright (c) 2002 by Secret Labs AB
  11. # Copyright (c) 2002 by Fredrik Lundh
  12. #
  13. # See the README file for information on usage and redistribution.
  14. #
  15.  
  16. import Image
  17.  
  18. class Transform:
  19.     def __init__(self, data):
  20.         self.data = data
  21.     def getdata(self):
  22.         return self.method, self.data
  23.  
  24. ##
  25. # Define an affine image transform.
  26. # <p>
  27. # This function takes a 6-tuple (<i>a, b, c, d, e, f</i>) which
  28. # contain the first two rows from an affine transform matrix. For
  29. # each pixel (<i>x, y</i>) in the output image, the new value is
  30. # taken from a position (a <i>x</i> + b <i>y</i> + c,
  31. # d <i>x</i> + e <i>y</i> + f) in the input image, rounded to
  32. # nearest pixel.
  33. # <p>
  34. # This function can be used to scale, translate, rotate, and shear the
  35. # original image.
  36. #
  37. # @def AffineTransform(matrix)
  38. # @param matrix A 6-tuple (<i>a, b, c, d, e, f</i>) containing
  39. #    the first two rows from an affine transform matrix.
  40. # @see Image#Image.transform
  41.  
  42. class AffineTransform(Transform):
  43.     method = Image.AFFINE
  44.  
  45. ##
  46. # Define a transform to extract a subregion from an image.
  47. # <p>
  48. # Maps a rectangle (defined by two corners) from the image to a
  49. # rectangle of the given size.  The resulting image will contain
  50. # data sampled from between the corners, such that (<i>x0, y0</i>)
  51. # in the input image will end up at (0,0) in the output image,
  52. # and (<i>x1, y1</i>) at <i>size</i>.
  53. # <p>
  54. # This method can be used to crop, stretch, shrink, or mirror an
  55. # arbitrary rectangle in the current image. It is slightly slower than
  56. # <b>crop</b>, but about as fast as a corresponding <b>resize</b>
  57. # operation.
  58. #
  59. # @def ExtentTransform(bbox)
  60. # @param bbox A 4-tuple (<i>x0, y0, x1, y1</i>) which specifies
  61. #    two points in the input image's coordinate system.
  62. # @see Image#Image.transform
  63.  
  64. class ExtentTransform(Transform):
  65.     method = Image.EXTENT
  66.  
  67. ##
  68. # Define an quad image transform.
  69. # <p>
  70. # Maps a quadrilateral (a region defined by four corners) from the
  71. # image to a rectangle of the given size.
  72. #
  73. # @def QuadTransform(xy)
  74. # @param xy An 8-tuple (<i>x0, y0, x1, y1, x2, y2, y3, y3</i>) which
  75. #   contain the upper left, lower left, lower right, and upper right
  76. #   corner of the source quadrilateral.
  77. # @see Image#Image.transform
  78.  
  79. class QuadTransform(Transform):
  80.     method = Image.QUAD
  81.  
  82. ##
  83. # Define an mesh image transform.  A mesh transform consists of one
  84. # or more individual quad transforms.
  85. #
  86. # @def MeshTransform(data)
  87. # @param data A list of (bbox, quad) tuples.
  88. # @see Image#Image.transform
  89.  
  90. class MeshTransform(Transform):
  91.     method = Image.MESH
  92.